
var schoolid = null;
var startType = null;
var mask = null;
var count = 0
var login_user = null
var isfirst = false

$(function() { // 初始化内容
	mui.plusReady();
	mask = mui.createMask(); //遮罩层
	mui.init();
	mui('#pullrefresh').pullRefresh({

		up: { //上拉加载
			height: 50, //可选.默认50.触发上拉加载拖动距离
			auto: true, //可选,默认false.自动上拉加载一次
			contentrefresh: "正在加载...",
			contentnomore: '没有更多数据了',
			callback: function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				window.setTimeout(function() {
					pullupRefresh()
				}, 500);
			}
		}

	})
	login_user = JSON.parse(localStorage.getItem('loginUser'));
	datetime_init();

	showPicker()

})




function showPicker() {
	(function($, doc) {
		$.ready(function() {
			//普通示例
			
			var showPickerButton = doc.getElementById("status")
			showPickerButton.addEventListener('tap', function(event) {
				var userPicker = new mui.PopPicker();
				var pickerdata = [{
					value: '审核中',
					text: '审核中'
				}, {
					value: '校长审核通过',
					text: '校长审核通过'
				}, {
					value: '校长审核不通过',
					text: '校长审核不通过'
				}]
				userPicker.setData(pickerdata);
				userPicker.show(function(items) {
					console.log("////////")
					showPickerButton.innerText = items[0].text;
					status = items[0].value;
					//loadAuditReccord(status);
				});
			}, false);
		});
	})(mui, document);
}



function pullupRefresh() {
	mui('#pullrefresh').pullRefresh().enablePullupToRefresh(isfirst);
	//loadAuditReccord('审核中')
}



function loadData() {
	loadAuditReccord('审核中')
	loadAuditReccord('校长审核通过')
	loadAuditReccord('校长审核不通过')

}


function loadAuditReccord(status) {
	var data = {};

	if (startType == "本月") {
		data['donetimestart'] = startCurrentMonth();
		data['donetimeend'] = endCurrentMonth();
	}


	data['page'] = 1 + count;
	data["rows"] = 20;
	data['xzauditstatus'] = status;
	data['schoolid'] = login_user.schoolid;
	data['type'] = "收入";
	console.log("成交记录=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "fxxz/skspGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层	
		},
		success: function(res) {

			mask.close(); //显示遮罩层 	  
			console.log("记录列表=====" + JSON.stringify(res));
			var recordList = res.tkList;
			//判断是否还有数据,没有就禁用上拉加载
			console.log(recordList.length)

			//数据加载完成后执行的操作,隐藏加载页面,显示数据
			if (isfirst == false) {
				count++
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //停止正在加载
				mui('#pullrefresh').pullRefresh().enablePullupToRefresh(); //显示上拉加载文字
			}
			switch (status) {
				case "审核中":
					//loadApp1(recordList);
					if (recordList.length < 20) {
						isfirst = true
						mui('#pullrefresh').pullRefresh().enablePullupToRefresh(isfirst);
					}
					break;
				case "校长审核通过":
					//loadApp2(recordList);
					if (recordList.length < 20) {
						isfirst = true
						mui('#pullrefresh').pullRefresh().enablePullupToRefresh(isfirst);
					}
					break;
				case "校长审核不通过":
					//loadApp3(recordList);
					if (recordList.length < 20) {
						isfirst = true
						mui('#pullrefresh').pullRefresh().enablePullupToRefresh(isfirst);
					}
					break
			}

		},
		error: function(e) {
			console.log("错误信息====" + JSON.stringify(e));
			mask.close(); //显示遮罩层
			var msg = e.responseJSON.message;
			var code = e.responseJSON.status;
			mui.alert('错误编码' + code + "\n" + "错误信息:" + msg);
			console.log("错误信息====" + JSON.stringify(e));
		}
	});



}


// var app1 = new Vue({
// 	el: '#app1',
// 	data: {
// 		show: true,
// 		todos: []
// 	},
// 	methods: {
// 		selected: function(todo) {
// 			var id = todo.id;

// 			mui.openWindow({
// 				url: 'knockdown_form.html',
// 				id: 'knockdown_form.html',
// 				extras: {
// 					recordid: id
// 				}
// 			});
// 		}
// 	}
// });

// var app2 = new Vue({
// 	el: '#app2',
// 	data: {
// 		show: true,
// 		todos: [],

// 	},
// 	methods: {
// 		selected: function(todo) {
// 			var id = todo.id;
// 			console.log("id=====" + id);

// 			mui.openWindow({
// 				url: 'knockdown_form.html',
// 				id: 'knockdown_form.html',
// 				extras: {
// 					recordid: id
// 				}
// 			});
// 		}
// 	}
// });
// var app3 = new Vue({
// 	el: '#app3',
// 	data: {
// 		show: true,
// 		todos: []
// 	},
// 	methods: {
// 		selected: function(todo) {
// 			var id = todo.id;
// 			console.log("id=====" + id);

// 			mui.openWindow({
// 				url: 'knockdown_form.html',
// 				id: 'knockdown_form.html',
// 				extras: {
// 					recordid: id
// 				}
// 			});
// 		}
// 	}
// });

// function loadApp1(data) {
// 	console.log("data1====" + JSON.stringify(data));

// 	for (var i = 0; i < data.length; i++) {
// 		var d = data[i];
// 		var o = new Object();
// 		for (var x in d) {
// 			o[x] = d[x];
// 		}
// 		o.imgsrc = '../../img/waitingimg.png';
// 		app1.todos.push(o);
// 	}


// }

// function loadApp2(data) {
// 	console.log("data2====" + JSON.stringify(data));
// 	for (var i = 0; i < data.length; i++) {
// 		var d = data[i];
// 		var o = new Object();
// 		for (var x in d) {
// 			o[x] = d[x];
// 		}
// 		o.imgsrc = '../../img/successimg.png'
// 		app2.todos.push(o);
// 	}
// }

// function loadApp3(data) {
// 	console.log("data3====" + JSON.stringify(data));

// 	for (var i = 0; i < data.length; i++) {
// 		var d = data[i];
// 		var o = new Object();
// 		for (var x in d) {
// 			o[x] = d[x];

// 		}
// 		o.imgsrc = '../../img/errorimg.png'
// 		app3.todos.push(o);

// 	}


// }
